<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Api extends Finecms_Controller {

	public function login()
	{

        $url = isset($_GET['url']) && $_GET['url'] ? urldecode($this->get('url')) : url('admin//');
        if ($this->isPostForm()) {
            $username = $this->post('username');
            $password = $this->post('password');
            $result = $this->user->check_login($username, $password);
            if ($result) {
                if ($result['site'] && $result['site'] != $this->siteid) {
                    $this->adminMsg(dr_lang('您无权管理该网站'));
                }
                $this->session->set_userdata('user_id', (int)$result['userid']);
                $this->adminMsg(dr_lang('登录成功'), $url, 3, 1, 1);
            } else {
                $this->adminMsg(dr_lang('登录失败'), url('admin/login', array('url'=>$this->get('url'))));
            }
        }

        $this->template->display('login.html');
	}

	public function main() {

        $this->template->display('main.html');
    }


    public function cache() {

        $caches = array(
            //'auth',
            //'ip',
            //'tag',
            //'block',
            //'theme',
            //'member',
            //'relatedlink',
        );

        //多网站模型缓存
        //多网站栏目缓存
        //多网站推荐位缓存
        //多网站联动菜单缓存
        foreach ($this->site_info as $sid => $t) {
            $caches[] = 'model-'.$sid;
            //$caches[] = 'category-'.$sid;
            //$caches[] = 'position-'.$sid;
            //$caches[] = 'linkage-'.$sid;
        }

        foreach ($caches as $name) {
            list($name, $sid) = explode('-', $name);
            $this->load->model(ucfirst($name), 'model');
            $this->model->cache((int)$sid);
        }
    }
}
